In [1]:
from math import pi, sin
The above expression brings in pi and sin from the math library.
In [2]:
pi # The constant pi
Out[2]:
In [3]:
sin(pi*1/2.) # The function sin
Out[3]:
You can also just import a library and not any particular function.
In [4]:
import math
math.e
Out[4]:
Finally in some cases you want to import a library, but the name of the library makes it cumbersome to use in your code. You can specify the name which you want to use for the library as follows.
In [5]:
import math as m
m.e
Out[5]: